package com.woniuxy.education.controller;


import com.woniuxy.education.entity.Allquestions;
import com.woniuxy.education.entity.CorrectTitle;
import com.woniuxy.education.entity.TeacherClass;
import com.woniuxy.education.service.MarkTestsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@CrossOrigin
@RestController
//试卷批阅
public class MarkTestsController {
    @Autowired
    MarkTestsService markTestsService;
    //作业批改
    //查询所有未批改的作业
    @RequestMapping("/findAll_homework")
    public Collection selectAllHomework(String userid){
        List list=null;
        //查询老师id对应班级id
      List<TeacherClass> tcs= markTestsService.selectClassId(userid);
     //   System.out.println(tcs);

        Collection values=null;
        if(tcs!=null){
            //查询未批改作业信息
           list=markTestsService.selectCompletedWork(tcs);
        }
    return list;
    }
    //批改指定学生作业前的查询
    @RequestMapping("/select_homework")
    public List selectHomework(int sid){

        //题目答案
        List<Allquestions> completedWorkAndTitle = markTestsService.getCompletedWorkAndTitle(sid);
       return completedWorkAndTitle;

    }
    //批改作业,未写完
    @RequestMapping("/correcting_homework")
    public boolean correctHomework(@RequestBody List<CorrectTitle> correctTitles){
        String str="";
        System.out.println(correctTitles);
        return markTestsService.correct(correctTitles);
        }
      //  System.out.println(s);
       // return list;




    //试卷批改
    //查询所有未批改的试卷
    @RequestMapping("/findAll_paper")
    public Collection selectAllPaper(String userid){
        List list=null;
        //查询老师id对应班级id
        List<TeacherClass> tcs= markTestsService.selectClassId(userid);
        //   System.out.println(tcs);

        Collection values=null;
        if(tcs!=null){
            //查询未批改试卷信息
            list=markTestsService.selectCompletedTest(tcs);
        }
        return list;
    }

    //批改指定学生试卷前的查询
    @RequestMapping("/selecttest")
    public List selecttest(int  tid){
        //System.out.println(tid);

        //题目答案
        List<Allquestions> completedtestAndTitle = markTestsService.getCompletedTestTitleAndAnswer(tid);

        return completedtestAndTitle;
       // return null;
    }
}
